/*
 * 遍历目录，读取到.project文件，输出工程相对于工作空间的路径
 *
 * */

var fs = require('fs');
var path = require('path');
var xml2js = require('xml2js');
var logger = require('log4js').getLogger();
var projects = [];

var traverse_dir = function (dir_location,projects) {
    var files = fs.readdirSync(dir_location);
    var project_file_index = files.indexOf(".project");
    if (project_file_index >= 0) {  //如果有.project 则说明该目录是一个工程目录 记录下来 返回
        projects.push(dir_location);
        //console.log(dir_location);
        //return;
    } else {
        for (var i in files) {
            if (files[i] != ".git") { //排除一部分目录 其实不只是.git
                var filename = dir_location + path.sep + files[i];
                var stat = fs.lstatSync(filename);
                if (stat.isDirectory() == true) {
                    traverse_dir(filename,projects);
                }
            }
        }
        //return;
    }
    //callback(null,projects);

};
module.exports.traverse_dir = traverse_dir;
module.exports.projects = projects;